-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
i18n: Relax sprintf arguments type #21919
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sprintf accepts a any number of positional arguments _or_ a map object of named arguments. Remove the string type.
Size Change: +13 B (0%) Total Size: 817 kB
ℹ️ View Unchanged
|
@alshakero @andrewserong This is relevant for Automattic/wp-calypso#41207 |
sirreal
changed the title
i18n: Open sprintf function type
i18n: Relax sprintf arguments type
Apr 27, 2020
sirreal
added
[Package] i18n
/packages/i18n
[Type] Code Quality
Issues or PRs that relate to code quality
labels
Apr 27, 2020
alshakero
approved these changes
Apr 27, 2020
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! I had some doubts about the added value of {...*}
but it's certainly better than nothing.
1 task
aduth
approved these changes
Apr 27, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Sprintf accepts a number of different inputs. The named object of replacements seems particularly important:
This is currently unsupported by the type
( format: string, ...args: string[] ) => string
, which requires a 0 or more strings to be passed after the format.Additionally, replacements may be a value for interpolation or a nullary function that returns a value for interpolation.
Remove the
string
restriction on replacement args. This aligns with what's currently on DefinitelyTyped.Other considerations
With TypeScript function overloads, we can write the following:
However, this seems to be poorly supported in TypeScript declarations via JSDoc: microsoft/TypeScript#25590
Here's my JSDoc translation, but it errors saying the function type must match the function signature:
Noticed in Automattic/wp-calypso#41207.
Types of changes
Bug fix: Relax rest args type of
sprintf
toany[]
.